package cn.hs.ph.dao.impl;

import cn.hs.ph.dao.userDao;
import cn.hs.ph.entity.User;
import cn.hs.ph.util.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class userDaoImpl implements userDao {

    @Override
    public User selectUsernameAndPwd(String username, String pwd) {
        String sql = "select * from user where username=? and password=?";
        Object obj[]={username,pwd};
        ResultSet set = JDBCDruidUtil.query(sql, obj);
        User user = null;
            try {
                if (set.next()){
                    user=new User(set.getInt(1),set.getString(2),set.getString(3));
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            JDBCDruidUtil.close();
        return user;
    }
}
